package com.nuonuo.test.config;

import org.hibernate.validator.HibernateValidatorConfiguration;
import org.springframework.boot.validation.MessageInterpolatorFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validator;
import java.util.Properties;

/**
 * @author duan
 * @version 1.0
 * @date 2023/10/12 10:06
 */
@Configuration
public class ValidatorConfig {

    @Bean
    public Validator validator() {
        LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
        MessageInterpolatorFactory interpolatorFactory = new MessageInterpolatorFactory();
        factoryBean.setMessageInterpolator(interpolatorFactory.getObject());
        Properties properties = new Properties();
        properties.put(HibernateValidatorConfiguration.ALLOW_PARAMETER_CONSTRAINT_OVERRIDE, "true" );
        factoryBean.setValidationProperties(properties);
        return factoryBean;
    }
}
